#include "../NewSyndrome-module.h"
#include <errno.h>
#include <time.h>

#ifdef WIN32
#include <winsock.h>

#else
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <sys/time.h>
#include <fcntl.h>
typedef struct sockaddr_in SOCKADDR_IN;
#endif

#define REQUETE_VERSION "0.5"

typedef struct _requete requete;
struct _requete
{
  int sock;
  char *buffer;
  unsigned int buffer_len;
  byte avt;
  char *ou;
  char *get;
  unsigned int timestart;
  unsigned int divers[5];
  void *p_divers;
  void (*fct_free_divers) (void *pdiv);
  int (*fct_parse_it) (requete * req);
  requete *next;
  requete *prev;
};

typedef struct _requete_conf requete_conf;
struct _requete_conf
{
  byte reperr;
  unsigned int timeout;
  unsigned int nbmax;
  unsigned int nbcur;
  unsigned int proxy_port;
  char proxy_addr[101];
  byte proxy_use;
};

enum { REQFAILURE, REQTIMEOUT };

requete *req_add_requete (const char *o, const char *re, int (*pfct) (requete * req), const char *host, int port);
void req_init_default (void);

byte reqs_are_connected (int fd, requete *pone);

int req_connexion_tcp (const char *serv, int port);
int req_data_in_wait (int sock);
int req_ready_to_send (int *sock);
void req_local_free (void *ptr);

extern requete_conf req_conf;
